﻿using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using SharpSqlAnalyzer.pp.mediator.type;

namespace SharpSqlAnalyzer.pp.mediator
{
	// Token: 0x02000268 RID: 616
	public class MediatorFactory
	{
		// Token: 0x06001361 RID: 4961 RVA: 0x0031EAC8 File Offset: 0x0031CCC8
		public static E getMediator<E>(Type clazz, string sessionId) where E : AbstractMediator
		{
			string key = sessionId + clazz.FullName;
			if (!MediatorFactory.mediator.ContainsKey(key))
			{
				Type typeFromHandle = typeof(MediatorFactory);
				lock (typeFromHandle)
				{
					if (!MediatorFactory.mediator.ContainsKey(key))
					{
						E e = (E)((object)clazz.GetConstructor(Type.EmptyTypes).Invoke(null));
						MediatorFactory.mediator[key] = e;
					}
				}
			}
			return (E)((object)MediatorFactory.mediator[key]);
		}

		// Token: 0x06001362 RID: 4962 RVA: 0x0031EB70 File Offset: 0x0031CD70
		public static E newInstance<E>(Type type) where E : AbstractMediator
		{
			return (E)((object)type.GetConstructor(Type.EmptyTypes).Invoke(null));
		}

		// Token: 0x06001363 RID: 4963 RVA: 0x0031EB88 File Offset: 0x0031CD88
		public static void clear(string sessionId)
		{
			object obj = MediatorFactory.@object;
			lock (obj)
			{
				IList<string> list = new List<string>();
				foreach (string text in MediatorFactory.mediator.Keys)
				{
					if (text.StartsWith(sessionId, StringComparison.Ordinal))
					{
						list.Add(text);
					}
				}
				foreach (string key in list)
				{
					MediatorFactory.mediator.Remove(key);
				}
			}
		}

		// Token: 0x0400149C RID: 5276
		private static volatile IDictionary<string, AbstractMediator> mediator = new ConcurrentDictionary<string, AbstractMediator>();

		// Token: 0x0400149D RID: 5277
		private static object @object = new object();
	}
}
